﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using YJKCodeBase.XmlUtility;
using YJKElementFinish.ColumnSurface.DataDefinition;

namespace YJKRoomDecorate.Kit
{
	public class RoomDecorateFormInfo
	{
		public int FormXPos { get; set; }

		public int FormYPos { get; set; }

		public bool IncludeMetope { get; set; }

		public bool IncludeCeiling { get; set; }

		public bool IncludeGround { get; set; }

		public bool IncludeSkirtline { get; set; }

		public bool MetopeTopToCeiling { get; set; }

		public bool MetopeIncludeColumn { get; set; }

		public string DefaultNameMetope { get; set; }

		public string DefaultNameCeiling { get; set; }

		public string DefaultNameGround { get; set; }

		public string DefaultNameSkirtline { get; set; }

		public double DefaultHighMetope { get; set; }

		public double DefaultHighCeiling { get; set; }

		public double DefaultHighGround { get; set; }

		public double DefaultHighSkirtline { get; set; }

		public double DefaultMetopeBottomOffset { get; set; }

		public List<string> SkirtlineNameList { get; set; }

		public List<WallTypeLayerInfos> MetopeTypeList { get; set; }

		public List<WallTypeLayerInfos> CeilingTypeList { get; set; }

		public List<WallTypeLayerInfos> GroundTypeList { get; set; }

		public RoomDecorateFormInfo(XmlHelper xmlHelper)
		{
			this.m_xmlHelper = xmlHelper;
			this.SkirtlineNameList = new List<string>();
			this.FormXPos = 50;
			this.FormYPos = 50;
			this.IncludeMetope = true;
			this.IncludeCeiling = true;
			this.IncludeGround = true;
			this.IncludeSkirtline = true;
			this.MetopeTopToCeiling = true;
			this.MetopeIncludeColumn = true;
			this.DefaultNameMetope = "";
			this.DefaultNameCeiling = "";
			this.DefaultNameGround = "";
			this.DefaultNameSkirtline = "";
			this.DefaultHighMetope = 2200.0;
			this.DefaultHighCeiling = 2200.0;
			this.DefaultHighGround = 0.0;
			this.DefaultHighSkirtline = 100.0;
			this.DefaultMetopeBottomOffset = 0.0;
			this.MetopeTypeList = new List<WallTypeLayerInfos>();
			this.CeilingTypeList = new List<WallTypeLayerInfos>();
			this.GroundTypeList = new List<WallTypeLayerInfos>();
			this.Init();
		}

		public bool Init()
		{
			if (this.m_xmlHelper.SelectNode(RoomDecorateFormInfo.g_strPos))
			{
				this.FormXPos = this.m_xmlHelper.GetValue(RoomDecorateFormInfo.g_strPosX).ToInt(0);
				this.FormYPos = this.m_xmlHelper.GetValue(RoomDecorateFormInfo.g_strPosY).ToInt(0);
			}
			else
			{
				this.m_xmlHelper.AddElement(RoomDecorateFormInfo.g_strPos);
			}
			if (this.m_xmlHelper.SelectNode(RoomDecorateFormInfo.g_strMetope))
			{
				this.IncludeMetope = this.m_xmlHelper.GetValue(RoomDecorateFormInfo.g_strInclude).ToBool(false);
				this.DefaultHighMetope = this.m_xmlHelper.GetValue(RoomDecorateFormInfo.g_strHigh).ToDouble(0.0);
				this.DefaultMetopeBottomOffset = this.m_xmlHelper.GetValue(RoomDecorateFormInfo.g_strMetopeOffset).ToDouble(0.0);
				this.DefaultNameMetope = this.m_xmlHelper.GetValue(RoomDecorateFormInfo.g_strName).ToString();
				this.MetopeTopToCeiling = this.m_xmlHelper.GetValue(RoomDecorateFormInfo.g_strMetopeToCeiling).ToBool(false);
				this.MetopeIncludeColumn = this.m_xmlHelper.GetValue(RoomDecorateFormInfo.g_strMetopeIncludeColumn).ToBool(false);
				List<WallTypeLayerInfos> metopeTypeList = new List<WallTypeLayerInfos>();
				this.GetElementType(ref metopeTypeList);
				this.MetopeTypeList = metopeTypeList;
			}
			else
			{
				this.m_xmlHelper.AddElement(RoomDecorateFormInfo.g_strMetope);
			}
			if (this.m_xmlHelper.SelectNode(RoomDecorateFormInfo.g_strCeiling))
			{
				this.IncludeCeiling = this.m_xmlHelper.GetValue(RoomDecorateFormInfo.g_strInclude).ToBool(false);
				this.DefaultHighCeiling = this.m_xmlHelper.GetValue(RoomDecorateFormInfo.g_strHigh).ToDouble(0.0);
				this.DefaultNameCeiling = this.m_xmlHelper.GetValue(RoomDecorateFormInfo.g_strName).ToString();
				List<WallTypeLayerInfos> ceilingTypeList = new List<WallTypeLayerInfos>();
				this.GetElementType(ref ceilingTypeList);
				this.CeilingTypeList = ceilingTypeList;
			}
			else
			{
				this.m_xmlHelper.AddElement(RoomDecorateFormInfo.g_strCeiling);
			}
			if (this.m_xmlHelper.SelectNode(RoomDecorateFormInfo.g_strGround))
			{
				this.IncludeGround = this.m_xmlHelper.GetValue(RoomDecorateFormInfo.g_strInclude).ToBool(false);
				this.DefaultHighGround = this.m_xmlHelper.GetValue(RoomDecorateFormInfo.g_strHigh).ToDouble(0.0);
				this.DefaultNameGround = this.m_xmlHelper.GetValue(RoomDecorateFormInfo.g_strName).ToString();
				List<WallTypeLayerInfos> groundTypeList = new List<WallTypeLayerInfos>();
				this.GetElementType(ref groundTypeList);
				this.GroundTypeList = groundTypeList;
			}
			else
			{
				this.m_xmlHelper.AddElement(RoomDecorateFormInfo.g_strGround);
			}
			if (this.m_xmlHelper.SelectNode(RoomDecorateFormInfo.g_strSkirtline))
			{
				this.IncludeSkirtline = this.m_xmlHelper.GetValue(RoomDecorateFormInfo.g_strInclude).ToBool(false);
				this.DefaultHighSkirtline = this.m_xmlHelper.GetValue(RoomDecorateFormInfo.g_strHigh).ToDouble(0.0);
				this.DefaultNameSkirtline = this.m_xmlHelper.GetValue(RoomDecorateFormInfo.g_strName).ToString();
				string text = this.m_xmlHelper.GetValue(RoomDecorateFormInfo.g_strSkirtlineFileList).ToString();
				this.SkirtlineNameList = text.Split(new char[]
				{
					';'
				}).ToList<string>();
				for (int i = 0; i < this.SkirtlineNameList.Count; i++)
				{
					if (this.SkirtlineNameList[i] == "")
					{
						this.SkirtlineNameList.RemoveAt(i);
						i--;
					}
				}
			}
			else
			{
				this.m_xmlHelper.AddElement(RoomDecorateFormInfo.g_strSkirtline);
			}
			return true;
		}

		private bool GetElementType(ref List<WallTypeLayerInfos> lstElementType)
		{
			foreach (XmlElement xmlElement in this.m_xmlHelper.GetElements())
			{
				if (!(xmlElement.Name != RoomDecorateFormInfo.g_strElementType))
				{
					string attribute = xmlElement.GetAttribute(RoomDecorateFormInfo.g_strName);
					List<WallLayerInfos> list = new List<WallLayerInfos>();
					foreach (object obj in xmlElement.ChildNodes)
					{
						XmlNode xmlNode = (XmlNode)obj;
						XmlElement xmlElement2 = xmlNode as XmlElement;
						string attribute2 = xmlElement2.GetAttribute(RoomDecorateFormInfo.g_strName);
						string attribute3 = xmlElement2.GetAttribute(RoomDecorateFormInfo.g_strElementTypeMaterial);
						string attribute4 = xmlElement2.GetAttribute(RoomDecorateFormInfo.g_strElementTypeThick);
						WallLayerInfos item = new WallLayerInfos(null, attribute2, attribute3, attribute4);
						list.Add(item);
					}
					WallTypeLayerInfos item2 = new WallTypeLayerInfos(attribute, 0, 0, list);
					lstElementType.Add(item2);
				}
			}
			foreach (WallTypeLayerInfos wallTypeLayerInfos in lstElementType)
			{
				XmlElement xmlElement3 = this.m_xmlHelper.AddElement(RoomDecorateFormInfo.g_strElementType);
				xmlElement3.SetAttribute(RoomDecorateFormInfo.g_strName, wallTypeLayerInfos.TypeName);
				foreach (WallLayerInfos wallLayerInfos in wallTypeLayerInfos.LayerList)
				{
					XmlElement xmlElement4 = this.m_xmlHelper.XmlDoc.CreateElement(RoomDecorateFormInfo.g_strElementTypeLayer);
					xmlElement3.AppendChild(xmlElement4);
					xmlElement4.SetAttribute(RoomDecorateFormInfo.g_strName, wallLayerInfos.Name);
					xmlElement4.SetAttribute(RoomDecorateFormInfo.g_strElementTypeThick, wallLayerInfos.Thickness);
					xmlElement4.SetAttribute(RoomDecorateFormInfo.g_strElementTypeMaterial, wallLayerInfos.MaterialName);
				}
			}
			return true;
		}

		private void SaveElementType(List<WallTypeLayerInfos> lstElementType)
		{
			int num = 0;
			int num2 = 10;
			foreach (WallTypeLayerInfos wallTypeLayerInfos in lstElementType)
			{
				num++;
				XmlElement xmlElement = this.m_xmlHelper.AddElement(RoomDecorateFormInfo.g_strElementType);
				xmlElement.RemoveAll();
				xmlElement.SetAttribute(RoomDecorateFormInfo.g_strName, wallTypeLayerInfos.TypeName);
				foreach (WallLayerInfos wallLayerInfos in wallTypeLayerInfos.LayerList)
				{
					XmlElement xmlElement2 = this.m_xmlHelper.XmlDoc.CreateElement(RoomDecorateFormInfo.g_strElementTypeLayer);
					xmlElement.AppendChild(xmlElement2);
					xmlElement2.SetAttribute(RoomDecorateFormInfo.g_strName, wallLayerInfos.Name);
					xmlElement2.SetAttribute(RoomDecorateFormInfo.g_strElementTypeThick, wallLayerInfos.Thickness);
					xmlElement2.SetAttribute(RoomDecorateFormInfo.g_strElementTypeMaterial, wallLayerInfos.MaterialName);
				}
				if (num > num2)
				{
					break;
				}
			}
		}

		public bool Save()
		{
			if (this.m_xmlHelper.SelectNode(RoomDecorateFormInfo.g_strPos))
			{
				this.m_xmlHelper.SetValue(RoomDecorateFormInfo.g_strPosX, this.FormXPos.ToString());
				this.m_xmlHelper.SetValue(RoomDecorateFormInfo.g_strPosY, this.FormYPos.ToString());
			}
			if (this.m_xmlHelper.SelectNode(RoomDecorateFormInfo.g_strMetope))
			{
				XmlElement xmlCurNode = this.m_xmlHelper.XmlCurNode;
				xmlCurNode.RemoveAll();
				this.m_xmlHelper.SetValue(RoomDecorateFormInfo.g_strInclude, this.IncludeMetope.ToString());
				this.m_xmlHelper.SetValue(RoomDecorateFormInfo.g_strHigh, this.DefaultHighMetope.ToString());
				this.m_xmlHelper.SetValue(RoomDecorateFormInfo.g_strMetopeOffset, this.DefaultMetopeBottomOffset.ToString());
				this.m_xmlHelper.SetValue(RoomDecorateFormInfo.g_strName, this.DefaultNameMetope);
				this.m_xmlHelper.SetValue(RoomDecorateFormInfo.g_strMetopeToCeiling, this.MetopeTopToCeiling.ToString());
				this.m_xmlHelper.SetValue(RoomDecorateFormInfo.g_strMetopeIncludeColumn, this.MetopeIncludeColumn.ToString());
				this.SaveElementType(this.MetopeTypeList);
			}
			if (this.m_xmlHelper.SelectNode(RoomDecorateFormInfo.g_strCeiling))
			{
				XmlElement xmlCurNode2 = this.m_xmlHelper.XmlCurNode;
				xmlCurNode2.RemoveAll();
				this.m_xmlHelper.SetValue(RoomDecorateFormInfo.g_strInclude, this.IncludeCeiling.ToString());
				this.m_xmlHelper.SetValue(RoomDecorateFormInfo.g_strHigh, this.DefaultHighCeiling.ToString());
				this.m_xmlHelper.SetValue(RoomDecorateFormInfo.g_strName, this.DefaultNameCeiling);
				this.SaveElementType(this.CeilingTypeList);
			}
			if (this.m_xmlHelper.SelectNode(RoomDecorateFormInfo.g_strGround))
			{
				XmlElement xmlCurNode3 = this.m_xmlHelper.XmlCurNode;
				xmlCurNode3.RemoveAll();
				this.m_xmlHelper.SetValue(RoomDecorateFormInfo.g_strInclude, this.IncludeGround.ToString());
				this.m_xmlHelper.SetValue(RoomDecorateFormInfo.g_strHigh, this.DefaultHighGround.ToString());
				this.m_xmlHelper.SetValue(RoomDecorateFormInfo.g_strName, this.DefaultNameGround);
				this.SaveElementType(this.GroundTypeList);
			}
			if (this.m_xmlHelper.SelectNode(RoomDecorateFormInfo.g_strSkirtline))
			{
				XmlElement xmlCurNode4 = this.m_xmlHelper.XmlCurNode;
				xmlCurNode4.RemoveAll();
				this.m_xmlHelper.SetValue(RoomDecorateFormInfo.g_strInclude, this.IncludeSkirtline.ToString());
				this.m_xmlHelper.SetValue(RoomDecorateFormInfo.g_strHigh, this.DefaultHighSkirtline.ToString());
				this.m_xmlHelper.SetValue(RoomDecorateFormInfo.g_strName, this.DefaultNameSkirtline);
				string text = "";
				if (this.SkirtlineNameList.Count > 0)
				{
					StringBuilder stringBuilder = new StringBuilder();
					foreach (string value in this.SkirtlineNameList)
					{
						stringBuilder.Append(value);
						stringBuilder.Append(";");
					}
					text = stringBuilder.ToString();
					text = text.Remove(text.Count<char>() - 1);
				}
				this.m_xmlHelper.SetValue(RoomDecorateFormInfo.g_strSkirtlineFileList, text);
			}
			this.m_xmlHelper.SaveXml("");
			return true;
		}

		private static string g_strPos = "Pos";

		private static string g_strPosX = "X";

		private static string g_strPosY = "Y";

		private static string g_strInclude = "IsInclude";

		private static string g_strHigh = "High";

		private static string g_strName = "Name";

		private static string g_strMetope = "Metope";

		private static string g_strMetopeOffset = "MetopeOffset";

		private static string g_strMetopeToCeiling = "IsMetopeToCeiling";

		private static string g_strMetopeIncludeColumn = "IsIncludeColumn";

		private static string g_strCeiling = "Ceiling";

		private static string g_strGround = "Ground";

		private static string g_strSkirtline = "Skirtline";

		private static string g_strSkirtlineFileList = "FileList";

		private static string g_strElementType = "ElementType";

		private static string g_strElementTypeLayer = "LayerType";

		private static string g_strElementTypeThick = "Thick";

		private static string g_strElementTypeMaterial = "MaterialType";

		private XmlHelper m_xmlHelper;
	}
}
